﻿using UnityEngine;
using System.Collections;

public class HitEvent : System.EventArgs
{
	public Square source;
	public Square target;
	public DamageInfo dmgInfo;
	public float occurTime;
}

public static class HitCaculate  {

	public static void CaculateHit(Body hurtObj, HitAction hitAct)
	{
		if (null == hitAct)
			return;

		// every hit-action only hurt target once during life circle.
		if (!hitAct.CheckValid (hurtObj))
		{
			Debug.Log("hited, don't check twice!!");
			return;
		}

		hitAct.AddIgnoreObj (hurtObj);

		// this valid attack
		HitEvent hitEvent = new HitEvent ();

		hitEvent.dmgInfo = hitAct.dmgInfo;
		hitEvent.source = hitAct.Creator;
		hitEvent.target = hurtObj.mainSquare;
		hitEvent.occurTime = Time.time;

		hurtObj.OnHit (hitEvent);
	}
}
